package com.glasses.primework;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import org.primefaces.event.SelectEvent;
import org.primefaces.model.tagcloud.DefaultTagCloudItem;
import org.primefaces.model.tagcloud.DefaultTagCloudModel;
import org.primefaces.model.tagcloud.TagCloudItem;
import org.primefaces.model.tagcloud.TagCloudModel;

@ManagedBean
public class TagCloudBean {
    private TagCloudModel model;
    
    public TagCloudModel getModel() {
        return model;
    }
    
    public void setModel(TagCloudModel model) {
        this.model = model;
    }
    
    public TagCloudBean() {
        model = new DefaultTagCloudModel();
        model.addTag(new DefaultTagCloudItem("Transformers", "#", 1));
        model.addTag(new DefaultTagCloudItem("La vie en rose", "#", 2));
        model.addTag(new DefaultTagCloudItem("Pirates of the Caribean", "#", 3));
        model.addTag(new DefaultTagCloudItem("Pan's Labyrinth", "#", 4));
        model.addTag(new DefaultTagCloudItem("Back to the Future", "#", 5));
        model.addTag(new DefaultTagCloudItem("Star Wars", "#", 6));
    }
    
    public void onSelect(SelectEvent event) {
        TagCloudItem item = (TagCloudItem) event.getObject();
        FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Item Selected", item.getLabel());
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
}
